package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.erp.bean.TouSuBean
import com.erp.mclass.QuanXian
import com.erp.R
import com.erp.activity.MainKActivity
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_tousu_item.view.*

/**
 * Created by Administrator on 2018/2/28/028.
 * 作者：刘洋
 */

class TouSuAdapter(private val mlist: List<TouSuBean>, private val mcontext: Context) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)

    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        val h: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_tousu_item, null)
            h = ViewHolder(v)
            v.tag = h
        } else {
            v=convertView
            h = convertView.tag as ViewHolder
        }
        val bean = mlist[position]
        if(QuanXian.isXiuGaiTouSuTudy){
            h.LlTudy.visibility=View.VISIBLE
            Myutil.settv(bean.duty_bumen, h.TvTudtBumen)
            Myutil.settv(bean.duty_name, h.TvTudtName)
        }
        if(MainKActivity.ZhuanMaiDianid != "0"){
            h.tvTiaoma.visibility = View.GONE
            h.tvGonghao.visibility = View.GONE
            Myutil.settv("姓名： "+bean.creator_name, h.tvName)
        }else{
            Myutil.settv(bean.chuangqu, h.tvTiaoma)
            Myutil.settv(bean.bumen, h.tvGonghao)
            Myutil.settv(bean.creator_name, h.tvName)
        }
        Myutil.settv(Myutil.getdata(bean.ctime), h.tvChuangjianTime)
        Myutil.settv(bean.tousu, h.tvTousu)
        Myutil.settv(bean.jianyi, h.tvJianyi)
        return v
    }

    class ViewHolder(v : View) {
        var tvTiaoma = v.TvTiaoma
        var tvGonghao = v.TvGonghao
        var tvName = v.TvName
        var tvChuangjianTime = v.TvChuangjianTime
        var tvTousu = v.TvTousu
        var tvJianyi = v.TvJianyi
        var LlTudy = v.LlTudy
        var TvTudtBumen = v.TvTudtBumen
        var TvTudtName = v.TvTudtName
    }
}
